package com.baidu.shoppingmall.auth.service.impl;

import com.baidu.shoppingmall.auth.composite.AuthorityNode01;
import com.baidu.shoppingmall.auth.dao.AuthorityDAO;
import com.baidu.shoppingmall.auth.domain.AuthorityDTO;
import com.baidu.shoppingmall.auth.domain.AuthorityPO;
import com.baidu.shoppingmall.auth.service.AuthorityService;
import com.baidu.shoppingmall.auth.service.AuthorityService01;
import com.baidu.shoppingmall.auth.visitor.CheckRoleAuthorityRelationVisitor01;
import com.baidu.shoppingmall.auth.visitor.DeleteAuthorityVisitor01;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AuthorityServiceImpl01 extends ServiceImpl<AuthorityDAO, AuthorityPO> implements AuthorityService01 {

    @Autowired
    private AuthorityDAO authorityDAO;

    @Autowired
    private CheckRoleAuthorityRelationVisitor01 checkRoleAuthorityRelationVisitor01;


    @Autowired
    private DeleteAuthorityVisitor01 deleteAuthorityVisitor01;

    @Override
    public Integer delete(Integer id) {

        AuthorityPO authorityPO = authorityDAO.selectById(id);
        //如果查询数据库中没有的数据就会返回一个空对象  所以应当做非空处理
        AuthorityNode01 authorityNode01 = authorityPO.clone(AuthorityNode01.class);
        checkRoleAuthorityRelationVisitor01.visit(authorityNode01);
        Boolean status = checkRoleAuthorityRelationVisitor01.getStatus();
        if (!status){
            deleteAuthorityVisitor01.visit(authorityNode01);
        }else {
            throw new RuntimeException("被占用");
        }
      return 1;
    }
}
